# Contributor: Fabricio Silva <hi@fabricio.dev>
# Maintainer: Fabricio Silva <hi@fabricio.dev>
pkgname=recyclarr-cli
pkgver=6.0.2
pkgrel=1
pkgdesc="Automatically sync TRaSH guides to your Sonarr and Radarr instances"
url="https://github.com/recyclarr/recyclarr"
arch="x86_64 aarch64 armv7"
license="MIT"
options="net !check !strip" # strip breaks the package
depends="
	dotnet8-runtime
	git
	"
makedepends="dotnet8-sdk"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/recyclarr/recyclarr/archive/refs/tags/v$pkgver.tar.gz
	0001-disable-gitversion.patch
	0002-build-dotnet8.patch
	"
builddir="$srcdir/recyclarr-$pkgver"

# map arch to dotnet
case $CARCH in
	x86_64) _dotnet_arch="x64" ;;
	aarch64) _dotnet_arch="arm64" ;;
	armv7) _dotnet_arch="arm" ;;
	*) _dotnet_arch="$CARCH" ;;
esac

prepare() {
	default_prepare

	# apply patch version
	sed -i "s/{Version}/$pkgver-r$pkgrel.alpine/" src/Recyclarr.Cli/Program.cs
}

build() {
	# build the package and generate artifact
	dotnet publish src/Recyclarr.Cli \
		-p:RuntimeIdentifier="linux-musl-$_dotnet_arch" \
		-p:Configuration=Release \
		-p:SelfContained=false \
		-p:PublishSingleFile=true \
		-p:DisableGitVersionTask=true \
		--output publish
}

package() {
	install -Dm755 publish/recyclarr -t "$pkgdir"/usr/bin
}

sha512sums="
70790aee093a2028d817223340a7ba98fb661a57bedbff6735a0d915108a085a80050996bf699dfaa81c34ed85511100eeaf31d90ecec8d798a619b1c47012d6  recyclarr-cli-6.0.2.tar.gz
68bbe5a566fabc49f3382c76550f1462f318ddcbfbad33300551b651ba36e853ce4fed2a39d9dae8e9de1309b2dd5cb73df6f78b9dff1d2a9983b8c0cddda357  0001-disable-gitversion.patch
40d47902cf83f302ed437049154c74b8df7db37009cab0bfdc8b9a1244e0ad20ce5d868680406a487733f9d4a80587454b215196f8830d69fe9fe0b0664f469e  0002-build-dotnet8.patch
"
